package cl.jpavlich.mpm.services;

import java.io.FileNotFoundException;
import java.io.InputStream;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.StaxDriver;

import de.schlichtherle.truezip.file.TFile;
import de.schlichtherle.truezip.file.TFileOutputStream;

public class Serializer {
	XStream xstream = new XStream(new StaxDriver());
	public void serialize(Object obj, TFile f) {
		try {
			xstream.toXML(obj,new TFileOutputStream(f));
		} catch (FileNotFoundException e) {
			throw new RuntimeException(e);
		}
	}
	
	@SuppressWarnings("unchecked")
	public <T> T deserialize(Class<T> rootClass, InputStream is) {
		return (T) xstream.fromXML(is);
	}
	

}
